class Topic < ActiveRecord::Base
  cattr_reader :per_page
  @@per_page = 20
  
  belongs_to :group
  belongs_to :user
  belongs_to :replied_by_user, :class_name => "User", :foreign_key => "replied_by"
  has_many :posts, :order => "created_at asc", :dependent => :delete_all
  
  validates_presence_of :title, :content
  format_attribute :content
  
  def editable_by?(user)
    user!=:false && (user.id == user_id || user.is_admin? || user.moderator_of?(self.group))
  end
end
